package com.hyst.web;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PatchMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.hyst.common.ResultBean;
import com.hyst.common.ResultPage;
import com.hyst.domain.Recommend;
import com.hyst.domain.RecommendRecord;
import com.hyst.service.RecommendRecordService;

/**
 * @Description:controller
 * @author：dy 
 *@Date：2018年09月26日
 */
@RestController
@RequestMapping("recommendRecords")
@CrossOrigin(maxAge = 3600, origins = "*")
public class RecommendRecordController {
	@Autowired
	private RecommendRecordService recommendRecordService;
	
	@GetMapping
	public ResultPage<RecommendRecord> list(RecommendRecord recommendRecord) {
		return ResultPage.success(recommendRecordService.list(recommendRecord));
	}

	@PostMapping
	public ResultBean<RecommendRecord> creat(final RecommendRecord recommendRecord) {
		return ResultBean.success(recommendRecordService.insert(recommendRecord));
	}

	/**
	 * @Description: 根据主键查询
	 * @param uniqueId
	 * @return ResultBean<RecommendRecord>
	 */
	@GetMapping("{uniqueId}")
	public ResultBean<RecommendRecord> getByPriKey(@PathVariable("uniqueId") final String uniqueId) {
		return ResultBean.success(recommendRecordService.getByPriKey(uniqueId));
	}

	/**
	 * @Description: 根据主键更新全字段
	 * @param recommendRecord
	 * @return ResultBean<RecommendRecord>
	 */
	@PatchMapping("{uniqueId}")
	public ResultBean<RecommendRecord> update(final RecommendRecord recommendRecord) {
		return ResultBean.success(recommendRecordService.update(recommendRecord));
	}

	/**
	 * @Description: 根据主键更新不为默认值的字段
	 * @param recommendRecord
	 * @return ResultBean<RecommendRecord>
	 */
	//@PutMapping("{uniqueId}")
	@PostMapping("{uniqueId}")
	public ResultBean<RecommendRecord> updatePatch(@PathVariable("uniqueId") final String uniqueId,
			final RecommendRecord recommendRecord) {
		return ResultBean.success(recommendRecordService.updateSelective(recommendRecord));
	}

	/**
	 * @Description: 根据主键删除
	 * @param uniqueId
	 * @return ResultBean<RecommendRecord>
	 */
	@DeleteMapping("{uniqueId}")
	public ResultBean<RecommendRecord> delete(@PathVariable("uniqueId") final String uniqueId) {
		return ResultBean.success(recommendRecordService.delete(uniqueId));
	}

	// 条件查询
	@GetMapping("selectByFuzeren/{fuzerenId}")
	public ResultPage<RecommendRecord> getByFuzerenId(final RecommendRecord recommendRecord,@PathVariable("fuzerenId") final String fuzerenId) {
		System.out.println(fuzerenId);
		return ResultPage.success(recommendRecordService.getDataByFuzerenId(recommendRecord,fuzerenId));
	}

}
